<%@page import="edu.asselvi.seguros.pojo.Item"%>
<%@page import="edu.asselvi.seguros.exception.SegurosException"%>
<%@page import="edu.asselvi.seguros.dao.ItemDao"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Processando...</title>
</head>
<body>


<%

	if (request.getParameter("acao").equals("REM")){
		
		try {
			new ItemDao().remove(Integer.parseInt(request.getParameter("idItem")));
		} catch (SegurosException e) {
			
		} 
		
		
		response.sendRedirect("detalhesContrato.jsp?idContrato=" + request.getParameter("idContrato"));
		
	} else if (request.getParameter("acao").equals("UPD")) {
		
		if (request.getParameter("edtDescricao") != null &&
			request.getParameter("edtDocumento") != null &&
			request.getParameter("edtAno") != null &&
			request.getParameter("edtValor") != null &&
			request.getParameter("edtFranquia") != null &&
			request.getParameter("edtIndenizacao") != null &&
			request.getParameter("idTipoItem") != null &&
			request.getParameter("idMarca") != null &&
			request.getParameter("idModelo") != null &&
			request.getParameter("idContrato") != null &&
			
			!request.getParameter("edtDescricao").equals("") &&
			!request.getParameter("edtDocumento").equals("") &&
			!request.getParameter("edtAno").equals("") &&
			!request.getParameter("edtValor").equals("") &&
			!request.getParameter("edtFranquia").equals("") &&
			!request.getParameter("edtIndenizacao").equals("") &&
			!request.getParameter("idTipoItem").equals("") &&
			!request.getParameter("idMarca").equals("") &&
			!request.getParameter("idModelo").equals("") &&
			!request.getParameter("idContrato").equals("")){
		
			
			
			String edtDescricao = request.getParameter("edtDescricao");
			String edtDocumento = request.getParameter("edtDocumento");
			int edtAno = Integer.parseInt(request.getParameter("edtAno"));
			double edtValor = Double.parseDouble(request.getParameter("edtValor"));
			double edtFranquia = Double.parseDouble(request.getParameter("edtFranquia"));
			double edtIndenizacao = Double.parseDouble(request.getParameter("edtIndenizacao"));
			int idTipoItem = Integer.parseInt(request.getParameter("idTipoItem"));
			int idMarca = Integer.parseInt(request.getParameter("idMarca"));
			int idModelo = Integer.parseInt(request.getParameter("idModelo"));
			int idContrato = Integer.parseInt(request.getParameter("idContrato"));			
			
			Item item = new Item(edtDescricao, edtDocumento, edtAno, edtValor, edtFranquia, edtIndenizacao, idTipoItem, idModelo, idContrato);
			
			try {
				ItemDao dao = new ItemDao();
				
				if (request.getParameter("idItem") != null){
					item.setId_item(Integer.parseInt(request.getParameter("idItem")));				
					dao.update(item);
				} else {
					dao.insert(item);
				}
			} catch (SegurosException e) {
				//I don't give a shit!
			}
			
			response.sendRedirect("manterItem.jsp?idContrato=" + request.getParameter("idContrato"));
			
		} else {
			
			response.sendRedirect("manterItem.jsp?idContrato=" + request.getParameter("idContrato"));
		}
	} else {
		
		response.sendRedirect("manterItem.jsp?idContrato=" + request.getParameter("idContrato"));
	}
	
%>



</body>
</html>